# Copyright (c) 2019-present, Facebook, Inc.
# All rights reserved.
#
# This source code is licensed under the license found in the
# LICENSE file in the root directory of this source tree.
#
def f_gold ( blockSize , m , processSize , n ) :
    allocation = [ - 1 ] * n
    for i in range ( n ) :
        wstIdx = - 1
        for j in range ( m ) :
            if blockSize [ j ] >= processSize [ i ] :
                if wstIdx == - 1 :
                    wstIdx = j
                elif blockSize [ wstIdx ] < blockSize [ j ] :
                    wstIdx = j
        if wstIdx != - 1 :
            allocation [ i ] = wstIdx
            blockSize [ wstIdx ] -= processSize [ i ]
    print ( "Process No.Process Size Block no." )
    for i in range ( n ) :
        print ( i + 1 , "         " , processSize [ i ] , end = "     " )
        if allocation [ i ] != - 1 :
            print ( allocation [ i ] + 1 )
        else :
            print ( "Not Allocated" )


#TOFILL

if __name__ == '__main__':
    param = [
    ([2, 3, 4, 4, 6, 9, 9, 9, 14, 16, 16, 20, 28, 29, 31, 34, 37, 39, 46, 51, 54, 60, 63, 63, 65, 65, 66, 68, 70, 75, 80, 83, 88, 90, 91, 96, 98],33,[2, 4, 6, 9, 10, 13, 14, 16, 20, 21, 33, 34, 35, 36, 43, 44, 49, 51, 51, 52, 55, 58, 59, 60, 65, 66, 66, 74, 78, 79, 83, 88, 88, 91, 94, 95, 97],31,),
    ([-44, -62, 0, 42, 78, 2, 88, 84, 48, -72, 76, -76, -42, 4, -56, -52, 46, -74, 66, 94, 32, -38, -36, 68, -70, 76, 32, -4, -48, -68, 96, 84, 20, 66, 86, 34, -8, -6, -84, 56, 50, 40, 70, 10, -2, 46, -10, -54],47,[-18, 38, -82, -54, -32, 32, 76, 54, 88, -50, -10, -66, 42, 34, -56, -38, -82, -4, 52, -78, 82, -32, 72, 84, 98, 88, -2, 60, 78, 68, -84, -58, 78, -98, -14, -20, -60, -94, 20, -48, 26, 2, -40, 76, -38, 38, -10, -52],25,),
    ([0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1],30,[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1],29,),
    ([50, 57, 42, 88, 13, 71, 49],3,[54, 56, 23, 71, 73, 58, 89],5,),
    ([-96, -94, -92, -84, -82, -80, -80, -76, -76, -72, -58, -46, -44, -40, -34, -24, -18, -16, -16, -10, -10, 2, 8, 10, 14, 20, 26, 36, 38, 42, 54, 54, 62, 64, 64, 64, 72, 78, 84, 86, 88, 94, 98],34,[-98, -92, -92, -88, -82, -76, -58, -58, -54, -50, -44, -32, -30, -28, -28, -18, -4, -4, 0, 2, 6, 10, 10, 14, 20, 22, 24, 26, 30, 38, 48, 48, 52, 62, 66, 78, 82, 88, 90, 92, 94, 94, 98],40,),
    ([0, 1, 0, 1, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 1, 1, 1, 1, 0, 1, 1, 0, 1, 0, 1, 1, 1, 1, 1, 0, 0, 1, 1, 1, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0],43,[0, 1, 1, 1, 0, 1, 0, 0, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 0, 0, 1, 1, 1, 1, 1, 0, 0, 1, 0, 1, 0, 1, 0, 1, 1, 1, 1],42,),
    ([10, 15, 19, 22, 34, 35, 36, 38, 38, 40, 42, 42, 43, 48, 48, 49, 50, 54, 56, 60, 69, 76, 77, 79, 79, 80, 82, 85, 90, 95, 96, 98, 98, 99],32,[2, 5, 6, 7, 8, 11, 11, 12, 19, 20, 25, 28, 33, 34, 42, 46, 46, 55, 59, 62, 63, 65, 66, 67, 70, 74, 76, 80, 81, 82, 86, 89, 95, 99],19,),
    ([-52, 56, -48, 38, 84, -20, -32, -38, 8, -36, -66, -64, -66, -56, -74, -30, 58, 22, -2, -50, -90, -4, -2, 44, -60, -22, 74, 38, -50, 30, 94, -32, 94, 44, 90, -82, -42, -24, 46, 10, -34, -8, 98, -14, -42, 84, -8, 54],42,[58, 88, 16, -18, 24, 14, -26, -28, -16, -88, -56, 32, 24, 22, 46, 48, 50, 0, 6, 84, 88, -50, -4, 14, -80, 42, 18, 2, 90, -8, -32, -2, 46, -30, -46, 32, 70, -46, -18, 2, 36, -2, -60, -30, 48, -14, 76, -96],43,),
    ([0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1],22,[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1],19,),
    ([75],0,[29],0,)
        ]
    filled_function_param = [
    ([2, 3, 4, 4, 6, 9, 9, 9, 14, 16, 16, 20, 28, 29, 31, 34, 37, 39, 46, 51, 54, 60, 63, 63, 65, 65, 66, 68, 70, 75, 80, 83, 88, 90, 91, 96, 98],33,[2, 4, 6, 9, 10, 13, 14, 16, 20, 21, 33, 34, 35, 36, 43, 44, 49, 51, 51, 52, 55, 58, 59, 60, 65, 66, 66, 74, 78, 79, 83, 88, 88, 91, 94, 95, 97],31,),
    ([-44, -62, 0, 42, 78, 2, 88, 84, 48, -72, 76, -76, -42, 4, -56, -52, 46, -74, 66, 94, 32, -38, -36, 68, -70, 76, 32, -4, -48, -68, 96, 84, 20, 66, 86, 34, -8, -6, -84, 56, 50, 40, 70, 10, -2, 46, -10, -54],47,[-18, 38, -82, -54, -32, 32, 76, 54, 88, -50, -10, -66, 42, 34, -56, -38, -82, -4, 52, -78, 82, -32, 72, 84, 98, 88, -2, 60, 78, 68, -84, -58, 78, -98, -14, -20, -60, -94, 20, -48, 26, 2, -40, 76, -38, 38, -10, -52],25,),
    ([0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1],30,[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1],29,),
    ([50, 57, 42, 88, 13, 71, 49],3,[54, 56, 23, 71, 73, 58, 89],5,),
    ([-96, -94, -92, -84, -82, -80, -80, -76, -76, -72, -58, -46, -44, -40, -34, -24, -18, -16, -16, -10, -10, 2, 8, 10, 14, 20, 26, 36, 38, 42, 54, 54, 62, 64, 64, 64, 72, 78, 84, 86, 88, 94, 98],34,[-98, -92, -92, -88, -82, -76, -58, -58, -54, -50, -44, -32, -30, -28, -28, -18, -4, -4, 0, 2, 6, 10, 10, 14, 20, 22, 24, 26, 30, 38, 48, 48, 52, 62, 66, 78, 82, 88, 90, 92, 94, 94, 98],40,),
    ([0, 1, 0, 1, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 1, 1, 1, 1, 0, 1, 1, 0, 1, 0, 1, 1, 1, 1, 1, 0, 0, 1, 1, 1, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0],43,[0, 1, 1, 1, 0, 1, 0, 0, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 0, 0, 1, 1, 1, 1, 1, 0, 0, 1, 0, 1, 0, 1, 0, 1, 1, 1, 1],42,),
    ([10, 15, 19, 22, 34, 35, 36, 38, 38, 40, 42, 42, 43, 48, 48, 49, 50, 54, 56, 60, 69, 76, 77, 79, 79, 80, 82, 85, 90, 95, 96, 98, 98, 99],32,[2, 5, 6, 7, 8, 11, 11, 12, 19, 20, 25, 28, 33, 34, 42, 46, 46, 55, 59, 62, 63, 65, 66, 67, 70, 74, 76, 80, 81, 82, 86, 89, 95, 99],19,),
    ([-52, 56, -48, 38, 84, -20, -32, -38, 8, -36, -66, -64, -66, -56, -74, -30, 58, 22, -2, -50, -90, -4, -2, 44, -60, -22, 74, 38, -50, 30, 94, -32, 94, 44, 90, -82, -42, -24, 46, 10, -34, -8, 98, -14, -42, 84, -8, 54],42,[58, 88, 16, -18, 24, 14, -26, -28, -16, -88, -56, 32, 24, 22, 46, 48, 50, 0, 6, 84, 88, -50, -4, 14, -80, 42, 18, 2, 90, -8, -32, -2, 46, -30, -46, 32, 70, -46, -18, 2, 36, -2, -60, -30, 48, -14, 76, -96],43,),
    ([0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1],22,[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1],19,),
    ([75],0,[29],0,)
        ]
    n_success = 0
    for i, parameters_set in enumerate(param):
        f_filled(*(filled_function_param[i]))
        f_gold(*parameters_set)
        if parameters_set == filled_function_param[i]:
            n_success+=1
    print("#Results: %i, %i" % (n_success, len(param)))